import {
    _headerPost,
    _headerGet,
    config,
} from '../../../../utils/httpUtils.js'
const app = getApp()
Page({
    data: {
        height: app.globalData.height
    },

    onLoad: function(options) {
        this.myNote(1)
    },

    myNote(pageNum, pageCount) {
        let data = {
            'page': pageNum,
            'pageCount': pageCount || 10
        }
        _headerGet('/api/user/my_dynamic', data, res => {
            console.log(res.data);
            if (res.data.code == 1 && JSON.stringify(res.data.data.dynamic_list) != "[]") {
                if (pageNum == 1) { //下拉重置数据
                    this.setData({
                        dynamic_list: res.data.data.dynamic_list,
                        userInfo: res.data.data.userInfo,
                        pageNum: pageNum
                    })
                } else {
                    this.setData({
                        dynamic_list: this.data.dynamic_list.concat(res.data.data),
                        userInfo: res.data.data.userInfo,
                        pageNum: pageNum
                    })
                }

            } else {
                wx.showToast({
                    title: '没有更多数据了',
                    duration: 2000,
                    icon: 'none'
                })
            }
            wx.stopPullDownRefresh()
        })
    },
    contDetail(e) { //个人中心,进详情
        let type = 1;
        let id = e.currentTarget.dataset.id;
        if (type == 2) {
            wx.navigateTo({
                url: `/pages/public/article_detail/article_detail?id=${id}`,
            })
        } else if (type == 1) {
            wx.navigateTo({
                url: `/pages/group/dynamicdetail/dynamicdetail?id=${id}`,
            })
        }
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.myNote(1)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        this.myNote(this.data.pageNum + 1)
    },
    // 返回上一页面
    _navback() {
        wx.navigateBack()
    },
})